#include "DataReader.hpp"
#include <stdexcept>
#include "PlayFinishException.hpp"

DataReader::DataReader()
{
}

void DataReader::RefreshData(std::filesystem::path path)
{
  coodList.clear();
  if(!std::filesystem::exists(path))
    throw std::runtime_error("指定目录下的文件不存在");
  std::ifstream file(path);
  if(!file.is_open())
    throw std::runtime_error("文件打开失败");
  std::array<Cood3D,25> tempArray;
  long items=0;
  while(file.good())
  {
    try
    {
	      items++;
	      if(items==644)
		throw std::exception();
      for(int i=0;i<25;i++)
      {

        //file>>tempArray[i].frameID;
        //file>>tempArray[i].jointIndex;
        //file>>tempArray[i].x;
        //file>>tempArray[i].y;
        //file>>tempArray[i].z;
        //file>>tempArray[i].jointOffset;
        //file>>tempArray[i].rotate_x;
        //file>>tempArray[i].rotate_y;
        //file>>tempArray[i].rotate_z;
        //file>>tempArray[i].rotate_joint;
        //if(!file.good())
        //  throw std::exception();
      }
    }
    catch(const std::exception & e)
    {
      break;
    }
    coodList.push_back(tempArray);
  }
  listptr=coodList.begin();
}

DataReader::~DataReader()
{

}

void DataReader::operator>>(std::array<Cood3D,25>& array)
{
  if(listptr==coodList.end())
    throw PlayFinishException();
  array=*listptr;
  listptr++;
}
